replace column values pandas

52

replace column values pandas -

df['column'] = df['column'].str.replace(',','-')
df

replace value in dataframe -

# this will replace "Boston Celtics" with "Omega Warrior"
df.replace(to_replace ="Boston Celtics",
                 value ="Omega Warrior")

python pandas change or replace value or cell name -

# 1. Replace a single value with a new value for an individual DataFrame column:
df['column name'] = df['column name'].replace(['old value'],'new value')

# 2. Replace multiple values with a new value for an individual DataFrame column:
df['column name'] = df['column name'].replace(['1st old value','2nd old value',...],'new value')

# 3. Replace multiple values with multiple new values for an individual DataFrame column:
df['column name'] = df['column name'].replace(['1st old value','2nd old value',...],['1st new value','2nd new value',...])

# 4. Replace a single value with a new value for an entire DataFrame:
df = df.replace(['old value'],'new value')


dataframe change column value -

df["column1"].replace({"a": "x", "b": "y"}, inplace=True)

Comments

Submit
0 Comments